import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import '../../config/public_color.dart';
import '../../config/public_text.dart';
import '../indicator/toast.dart';

/// FileName long_press_copy_text
///
/// @Author lax
/// @Date 2024/4/24
///
/// @Description

class LongPressCopyText extends StatelessWidget {
  final String? text;

  late final TextStyle? style;

  final EdgeInsets? padding;

  final TextAlign? textAlign;

  LongPressCopyText({
    super.key,
    this.text,
    TextStyle? style,
    this.padding,
    this.textAlign,
  }) {
    this.style = style ?? TextStyle(fontSize: 14, color: PublicColor.darkText);
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Container(
        color: padding == null ? null : Colors.transparent,
        padding: padding,
        child: Text(
          text ?? '',
          style: style,
          textAlign: textAlign,
        ),
      ),
      onLongPress: () {
        if (text != null) {
          Clipboard.setData(ClipboardData(text: text ?? ''));
          Toast.show(PublicText.copySuccess);
        }
      },
    );
  }
}
